﻿using System.Web.Http;
using WebActivatorEx;
using Swagger.Web.Api;
using Swashbuckle.Application;
using System;
using System.Xml.XPath;

[assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")]

namespace Swagger.Web.Api
{
    public class SwaggerConfig
    {
        public static void Register()
        {
            var thisAssembly = typeof(SwaggerConfig).Assembly;

            GlobalConfiguration.Configuration
                .EnableSwagger(c =>
                    {
                        c.SingleApiVersion("v1", "Swagger.Web.Api");

                        c.IncludeXmlComments(GetXmlCommentsPath());
                        
                    })
                .EnableSwaggerUi(c =>
                    {
                        c.DocumentTitle("My Swagger UI");
                    });
        }
		/// <summary>
		/// 获取xml文件
		/// </summary>
		/// <returns></returns>
		protected static string GetXmlCommentsPath()
		{
			return System.String.Format(@"{0}\bin\Swagger.Web.Api.xml", System.AppDomain.CurrentDomain.BaseDirectory);
		}
	}
}
